const { readDirInfo, saveJson, getFileCon } = require("../utils");
const Router = require('koa-router')
const router = new Router()
router.post('/saveProduction', async (ctx) => {
  //{a: '', goodsName: '', pageNum: '1', pageSize: '1'}
  const {json, name} = ctx.request.body
  const data = await saveJson(json, name?name:Date.now())
  ctx.body = {
    code: 200,
    data
  }
});
//获取商品
router.get('/getProduction', async (ctx) => {
  //{a: '', goodsName: '', pageNum: '1', pageSize: '1'}
  const data = await readDirInfo()
  
  ctx.body = {
    code: 200,
    data
  }
});
router.get('/getProductionDetail', async (ctx) => {
  //{a: '', goodsName: '', pageNum: '1', pageSize: '1'}
  const {id} = ctx.query
  const data = await getFileCon(id)
  
  ctx.body = {
    code: 200,
    data
  }
});

module.exports = router